from datetime import datetime
from sqlalchemy import Column, Integer, String, DateTime, Date, PrimaryKeyConstraint, Index

from config.database import Base


class KylinFutureSettlement(Base):
    """
    期货结算单表
    """

    __tablename__ = 'kylin_future_settlement'
    __table_args__ = (
        Index(
            'idx_account_date_type',
            'account_code',
            'settlement_date',
            'settlement_type',
            'profit_calc_type',
            unique=True,
        ),
        {'comment': '期货结算单'},
    )

    id = Column(Integer, primary_key=True, autoincrement=True, comment='结算单id')
    account_code = Column(String(20), nullable=False, comment='账户代码')
    settlement_date = Column(Date, nullable=False, comment='结算日期')
    settlement_type = Column(String(1), nullable=False, default='D', comment='结算单类型：D(日报)、M(月报)')
    profit_calc_type = Column(
        String(10), nullable=False, default='day', comment='盈亏计算方式：day(逐日盯市)、trade(逐笔对冲)'
    )
    file_name = Column(String(255), nullable=False, comment='文件名')
    settlement_status = Column(
        String(10), nullable=False, default='0', comment='结算单状态：0(未下载)、1(已下载)、2(已入库)'
    )
    create_time = Column(DateTime, default=datetime.now, comment='创建时间')
    update_time = Column(DateTime, default=datetime.now, onupdate=datetime.now, comment='更新时间')
